<?php

namespace App\Models\Chat;

use App\Models\BaseModel;
use App\Models\ChatUsers;
use Illuminate\Database\Eloquent\Model;


/**
 * Model ChatFriendModel
 *
 * @property int $id
 * @property int $uid
 * @property int $fid
 * @property string $remark
 * @property string $pinyin
 * @property int $status
 * @property string $add_time
 * @property string $created_at
 * @property string $updated_at
 * @property string group_name
 * @property int $group_sort
 *
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel get($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel first($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel select($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendModel orderBy($column, $direction = 'asc')
 * @package App\Model
 */

class ChatFriendModel extends BaseModel
{
    protected $table = 'chat_friend';

    public function filter($data)
    {
        //
        $where = [];
        if (isset($data['id']))
        {
            $where[] = ['id', '=', $data['id']];
        }
        if (isset($data['is_valid']))
        {
            $where[] = ['is_valid', '=', $data['is_valid']];
        }
        $this->getQueryByModel()->where($where);

        if ($this->getQueryByModel()->hasNamedScope("filter") && class_exists($this->getModelFilterClass())) {
            $this->getQueryByModel()->filter($data);
        }

        return $this->getQueryByModel();
    }

    public function friendInfo()
    {
        return $this->hasOne(ChatUsers::class,'id','fid');
    }
}
